package com.yc.controller;


import com.yc.entity.Cartoon;
import com.yc.mapper.CartoonMapper;
import com.yc.service.ICartoonService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * InnoDB free: 4096 kB 前端控制器
 * </p>
 *
 * @author ly
 * @since 2022-05-25
 */
@Controller
@RequestMapping("//cartoon")
public class CartoonController {
    @Resource
    private CartoonMapper cartoonMapper;

    @Resource
    private ICartoonService iCartoonService;

    @RequestMapping("queryAll")
    @ResponseBody
    public List< Cartoon > queryAll(){
        List<Cartoon> list=cartoonMapper.selectList(null);
        return list;
    }

    @RequestMapping("map")
    @ResponseBody
    public List<Cartoon> map(){
        return iCartoonService.map();
    }

    @RequestMapping("banner")
    @ResponseBody
    public List<Cartoon> banner(){
        return iCartoonService.banner();
    }

    @RequestMapping("queryByCtid")
    @ResponseBody
    public List< Cartoon > queryByCtid(Integer ctid){
        List< Cartoon > list=new ArrayList<>();
        list.add(cartoonMapper.selectById(ctid));
        return list;
    }

    @RequestMapping("queryByCsname")
    @ResponseBody
    public List< Cartoon > queryByCsname(String csname){
        return cartoonMapper.queryByCsname(csname);
    }

    @RequestMapping("queryByDate")
    @ResponseBody
    public List<Cartoon> queryByDate(String date){
        return iCartoonService.queryByDate(date);
    }

    @RequestMapping("queryByTypes")
    @ResponseBody
    public List<Cartoon> queryByTypes(@RequestBody List<String> types){
        return iCartoonService.queryByTypes(types);
    }

    @RequestMapping("queryByTypesOrderByCscore")
    @ResponseBody
    public List<Cartoon> queryByTypesOrderByCscore(@RequestBody List<String> types){
        return iCartoonService.queryByTypesOrderByCscore(types);
    }

    @RequestMapping("addCartoon")
    @ResponseBody
    public Integer addCartoon(@RequestBody List<Cartoon> list){
        return iCartoonService.addCartoon(list.get(0));
    }

    @RequestMapping("queryByCname")
    @ResponseBody
    public List<Cartoon> queryByCname(String cname){
        return iCartoonService.queryByCname(cname);
    }

    @RequestMapping("deleteByCtid")
    @ResponseBody
    public Integer deleteByCtid(Integer ctid){
        return iCartoonService.deleteByCtid(ctid);
    }

    @RequestMapping("update")
    @ResponseBody
    public Integer update(@RequestBody List<Cartoon> list){
        return iCartoonService.update(list.get(0));
    }

    @RequestMapping("queryCname")
    @ResponseBody
    public  List< Cartoon > queryCname(String cname){
        return iCartoonService.queryCname(cname);
    }

    @RequestMapping("queryBydirector")
    @ResponseBody
    public  List< Cartoon > querydirector(String  director){
        return iCartoonService.querydirector(director);
    }

    @RequestMapping("queryByprota")
    @ResponseBody
    public  List<Cartoon> queryprota(String prota){
        return  iCartoonService.queryprota(prota);
    }

    @RequestMapping("queryByctype")
    @ResponseBody
    public List<Cartoon> queryctype(String ctype){
        return  iCartoonService.queryctype(ctype);
    }

    @RequestMapping("queryjimdoo")
    @ResponseBody
    public List<Cartoon> queryjimdoo(String classname, String ctype, String time, String version,String qtype) {
        if ( qtype.equals("new") ){
            qtype="last_date";
        }else if(qtype.equals("hot")){
            qtype="commentnum";
        }else if ( qtype.equals("score") ){
            qtype="cscore";
        }
        return cartoonMapper.queryjimdoo(classname, ctype, time , version,qtype);
    }
}

